package com.lxc.graduation.config;

import com.lxc.graduation.interceptor.CorsInterceptor;
import com.lxc.graduation.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: ck
 * @Description: 跨域配置
 * @Date: Create in 18:14 2020/7/8
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Bean
    CorsInterceptor corsInterceptor(){
        return new CorsInterceptor();
    }
    @Bean
    LoginInterceptor loginInterceptor(){
        return new LoginInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //跨域配置 拦截全部接口
        registry.addInterceptor(corsInterceptor()).addPathPatterns("/**");
        registry.addInterceptor(loginInterceptor()).addPathPatterns("/api/v1/pri/*/*/**")
                .excludePathPatterns("/api/v1/pri/user/login","/api/v1/pri/user/register");
        WebMvcConfigurer.super.addInterceptors(registry);


    }
}
